package com.kgcx.coupon.controller;

import com.github.pagehelper.PageHelper;
import com.kgcx.common.bean.ReturnData;
import com.kgcx.common.controller.BaseController;
import com.kgcx.coupon.domain.MarketingPlan;
import com.kgcx.coupon.query.MarketingPlanQuery;
import com.kgcx.coupon.service.MarketingPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 何凯
 * @version 0.1
 * @description
 * @time 2017/12/12 15:01
 * @since 0.1
 */
@Api(description = "营销计划", tags = "营销计划接口")
@RestController
@RequestMapping("coupon/v1/plan")
public class MarketingPlanController extends BaseController{
    @Autowired
    private MarketingPlanService marketingPlanService;

    /**
     * 营销计划分页查询
     * @param query
     * @return
     */
    @ApiOperation(value = "营销计划分页查询", httpMethod = "POST", notes = "营销计划分页查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页容量", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderBy", value = "排序", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @PostMapping(value = "queryWithPage")
    public ReturnData<List<MarketingPlan>> queryMarketingPlanWithPage(@RequestBody MarketingPlanQuery query){
        PageHelper.startPage(query.getPageNum(),query.getPageSize());
        List<MarketingPlan> list= marketingPlanService.queryMarketingPlanList(query);
        return new ReturnData<>(list);
    }

    /**
     * 新增方案计划
     * @param plan
     * @return
     */
    @ApiOperation(value = "营销计划新增", httpMethod = "POST", notes = "营销计划新增接口")
    @PostMapping(value = "save")
    public ReturnData saveMarketingPlan(@RequestBody MarketingPlan plan){
            marketingPlanService.saveMarketingPlan(plan);
        return  new ReturnData();
    }

    /**
     * 修改营销方案
     * @param plan
     * @return
     */
    @ApiOperation(value = "营销计划修改", httpMethod = "POST", notes = "营销计划修改接口")
    @PostMapping(value = "update")
    public ReturnData updateMarketingPlan(@RequestBody MarketingPlan plan){
            marketingPlanService.updateMarketingPlan(plan);
         return  new ReturnData();
    }

    /**
     * 修改营销方案
     * @param kid
     * @return
     */
    @ApiOperation(value = "营销计划查看", httpMethod = "GET", notes = "营销计划查看接口")
    @GetMapping(value = "get")
    public ReturnData<MarketingPlan> getMarketingPlan(@RequestParam Integer kid){
         MarketingPlan plan = marketingPlanService.selectByPrimaryKey(kid);
         return  new ReturnData<>(plan);
    }

    /**
     * 获取所有营销方案
     * @return
     */
    @ApiOperation(value = "获取所有营销方案", httpMethod = "GET", notes = "获取所有营销方案接口")
    @GetMapping(value = "getAll")
    public ReturnData<List<MarketingPlan>> getAllMarketingPlan(){
         PageHelper.startPage(1,1000);
         MarketingPlanQuery query = new MarketingPlanQuery();
         List<MarketingPlan> plans = marketingPlanService.getAllMarketingPlan(query);
         return  new ReturnData<>(plans);
    }

}
